package main



import (
	"fmt"
	"math/rand"
	"time"
)

func main()  {
	test2()
	test3()
	test4()


}


/*
练习2：求两个3*3矩阵的和并输出（数据都是int类型）
	解析：矩阵的和计算规则是对应元素相加：
	c[i][j] = a[i][j] + b[i][j]
*/

func test2() {
	a := [3][3]int{{1,2,3},{4,5,6},{7,8,9}}
	b := [3][3]int{{1,2,3},{4,5,6},{7,8,9}}
	var c[3][3] int
	//a[0][0]
	for i := 0; i<3; i++ {
		for j := 0; j<3; j++{
			c[i][j] = a[i][j] + b[i][j]
		}
	}
	fmt.Println(c)

}




/*
练习3：使用go编写随机点名系统
	切片类型存放全班同学的名字：["史伟名","易鸽玲"]
	按任意键，不限次数随机抽取切片中的某一个同学名字回答问题
			 抽取到的同学就从切片中删除
	按q退出，或者切片里面所有的同学都已近被抽到
*/

func test3()  {
	var names string
	var classmates []string
	classmates = append(classmates,"史伟名","易鸽玲","唐瑞溪","张三","李四","王五")
	fmt.Println(classmates)
	//定义同学人数
	num1 := len(classmates)
	fmt.Println(num1)
	for {
		fmt.Println("请输入任意键开始抽取人数，按q退出：")
		fmt.Scanln(&names)
		if names == "q" {
			break
		}else {
			// 初始化随机种子
			rand.Seed(time.Now().Unix())

			// 生成一个 的随机整数
			random := rand.Intn(num1)
			fmt.Println("抽中",classmates[random])
			//将抽中的人员删除
			classmates = append(classmates[:random], classmates[random+1:]...)
			num1--
			if num1 ==0{
				break
			}
		}
	}


}

/*
练习4：验证用户名密码是否正确
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"158xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
	输入用户名密码，进行验证，验证成功后，输出手机号码
*/
func test4()  {
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"158xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
	var username string
	var passwd string
	fmt.Println("请输入用户名:")
	fmt.Scanln(&username)
	fmt.Println("请输入密码：")
	fmt.Scanln(&passwd)
	for usernames,userinfo := range userList{
		if username == usernames{
			if passwd == userinfo["password"] {
				fmt.Printf("%v的手机号码是：%v",username,userinfo["tel"])
			}else {
				fmt.Println("用户名或密码错误")
			}
		}else {
			fmt.Println("用户名或密码错误")
		}
		break
	}
}